package com.scx.util;

/**
 * String辅助工具类
 * @author using
 *
 */
public class StringUtil {

	/**
	 * 首字母转换大写
	 */
	public static final String upperFirst(String s) {
		int len = s.length();
		if (len <= 0) {
			return "";
		}

		StringBuffer sb = new StringBuffer();
		sb.append(s.substring(0, 1).toUpperCase());
		sb.append(s.substring(1, len));
		return sb.toString();
	}

	/**
	 * 首字母转换小写
	 */
	public static final String lowerFirst(String s) {
		int len = s.length();
		if (len <= 0) {
			return "";
		}

		StringBuffer sb = new StringBuffer();
		sb.append(s.substring(0, 1).toLowerCase());
		sb.append(s.substring(1, len));
		return sb.toString();
	}

	/**
	 * 全部转换小写
	 */
	public static final String lowerAll(String s) {
		int len = s.length();
		if (len <= 0) {
			return "";
		}
		return s.toLowerCase();
	}

	/**
	 * 全部转换大写
	 */
	public static final String upperAll(String s) {
		int len = s.length();
		if (len <= 0) {
			return "";
		}
		return s.toUpperCase();
	}

	/**
	 * 全符转换为小写，出现_替换掉，_后一个字母转换大写
	 * @param s xxx_xxx_xx
	 */
	public static final String removalUnderlinedUpperFirst(String s) {
		int len = s.length();
		if (len <= 0) {
			return "";
		}
		StringBuffer sb = new StringBuffer();
		String[] temp = s.split("_");
		for (int i = 0; i < temp.length; i++) {
			sb.append(upperFirst(temp[i].toString().toLowerCase()));
		}
		return sb.toString();
	}

	public static void main(String[] args) {
		System.out.println(removalUnderlinedUpperFirst("FORE_COMP_INFO"));
	}
}
